package com.gzw.dms.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gzw.dms.R;
import com.gzw.dms.bean.AbnormalReportInfo;

import java.util.List;

/**
 * Created by Administrator on 2016/8/11.
 */
public class AbonrmalAdapter extends RecyclerView.Adapter{
    public static interface OnRecyclerViewListener {
        void onItemClick(int position);
        boolean onItemLongClick(int position);
    }
    private OnRecyclerViewListener onRecyclerViewListener;
    public void setOnRecyclerViewListener(OnRecyclerViewListener onRecyclerViewListener) {
        this.onRecyclerViewListener = onRecyclerViewListener;
    }
    private static final String TAG = AbonrmalAdapter.class.getSimpleName();
    private List<AbnormalReportInfo> list;
    public AbonrmalAdapter(List<AbnormalReportInfo> list) {
        this.list = list;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_abonmal, null);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(lp);
        return new PersonViewHolder(view);
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
        PersonViewHolder holder = (PersonViewHolder) viewHolder;
        holder.position = i;
        AbnormalReportInfo mapInfo = list.get(i);
        holder.agreement_number.setText("货运编号:" + "  " + mapInfo.getShippingOrder().getShiping_order_num());
        holder.time.setText("收货联系人:"+"  "+mapInfo.getShippingOrder().getReceipt_name());
        holder.car_name.setText("出货订单号:" + "  " + mapInfo.getShippingOrder().getShiping_order_goid());
        holder.order_type.setText("起运时间:"+"  "+mapInfo.getShippingOrder().getSend_time());
        holder.send_mechanism.setText("受理机构:"+"  "+mapInfo.getShippingOrder().getSend_mechanism());

//        mHolder.all_money.setText("总运费:"+"  "+driverInfo.getReceipt());
//        String pay_state = mapInfo.getAbnormal_type();
//
//        if (pay_state.equals("1")) {
//            holder.order_type.setText("异常类型: 货物异常 ");
//
//        } else if (pay_state.equals("2")) {
//            holder.order_type.setText("异常类型: 客户异常");
//
//        }

        }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class PersonViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
        public View rootView;
        public TextView agreement_number;
        public TextView time;
        public TextView car_name;
        public TextView order_type;
        public TextView send_mechanism;

        public int position;
        public PersonViewHolder(View itemView) {
            super(itemView);
            agreement_number = (TextView) itemView.findViewById(R.id.order_textView);
            time = (TextView) itemView.findViewById(R.id.order_type);
            car_name = (TextView) itemView.findViewById(R.id.car_name);
            order_type = (TextView) itemView.findViewById(R.id.money);
            send_mechanism = (TextView) itemView.findViewById(R.id.send_mechanism);

            rootView = itemView.findViewById(R.id.ll);
            rootView.setOnClickListener(this);
            rootView.setOnLongClickListener(this);
        }
        @Override
        public void onClick(View v) {
            if (null != onRecyclerViewListener) {
                onRecyclerViewListener.onItemClick(position);
            }
        }
        @Override
        public boolean onLongClick(View v) {
            if (null != onRecyclerViewListener) {
                return onRecyclerViewListener.onItemLongClick(position);
            }
            return false;
        }
    }
}
